#!/bin/bash

FAKE_CONFIG="$(cat "${KUBECONFIG}" 2>/dev/null)"

if [[ "${*}" == *"config"* ]]; then
  cat <<-EOF
{
    "clusters": [
        {
            "cluster": {
                "server": "https://127.0.0.1"
            }
        }
    ]
}
EOF
exit 0
fi
if [[ "${*}" == *"version"* ]]; then
  cat <<EOF
{
  "clientVersion": {
    "major": "1",
    "minor": "19",
    "gitVersion": "v1.19.2",
    "gitCommit": "f5743093fd1c663cb0cbc89748f730662345d44d",
    "gitTreeState": "clean",
    "buildDate": "2020-09-16T13:41:02Z",
    "goVersion": "go1.15",
    "compiler": "gc",
    "platform": "linux/amd64"
  },
  "serverVersion": {
    "major": "1",
    "minor": "16+",
    "gitVersion": "v1.16.12-gke.1337",
    "gitCommit": "c56469002ffea532564027018cc503fdea159974",
    "gitTreeState": "clean",
    "buildDate": "2020-09-21T09:20:42Z",
    "goVersion": "go1.12.17b4",
    "compiler": "gc",
    "platform": "linux/amd64"
  }
}
EOF
  exit 0
fi
if [[ "${*}" == *"ns"* ]]; then
  cat <<EOF
NAME              STATUS   AGE
default           Active   53d
foo               Active   51d
gke-connect       Active   53d
istio-system      Active   37m
kube-node-lease   Active   53d
kube-public       Active   53d
kube-system       Active   53d
EOF
  exit 0
fi
if [[ "${*}" == *"clusterrolebinding"*"this_should_pass"* ]]; then
  echo '[cluster-admin]'
  exit 0
fi
if [[ "${FAKE_CONFIG}" == *"has_istio"*"right_namespace"*  ]]; then
  echo "istiod"
  exit 0
fi
if [[ "${FAKE_CONFIG}" == *"has_istio"*"wrong_namespace"* ]]; then
  if [[ "${*}" == *"istio-system"* ]]; then
    exit 0
  fi
  echo "istiod"
  exit 0
fi
